#include <tsin/library/DynamicLoopList.hpp>

#include <tsin/util/Logger.hpp>

using namespace tsin;

DynamicLoopList::DynamicLoopList()
        : current(0)
{
}

DynamicObject *DynamicLoopList::copy()
{
        return DynamicObject::copy(new DynamicLoopList);
}

void DynamicLoopList::reinit()
{
        current = 0;
        arguments[current]->reinit();
}

DynamicEvent DynamicLoopList::postTick(void *data, void *priv_data)
{
        DynamicEvent event = arguments[current]->postTick(data, priv_data);
        if (event & EVENT_END) {
                if (current == nrArguments - 1)
                        current = 0;
                else
                        current ++;
                arguments[current]->reinit();
        }
        return EVENT_REINIT;
}

char DynamicLoopList::getDescriptor()
{
        if (nrArguments == 0)
                return '?';
        return arguments[0]->getDescriptor();
}

int DynamicLoopList::getInt()
{
        return arguments[current]->getInt();
}

float DynamicLoopList::getFloat()
{
        return arguments[current]->getFloat();
}

bool DynamicLoopList::getBool()
{
        return arguments[current]->getBool();
}

